﻿using System;
using System.Windows;

namespace Utility3D
{
    public class IntersectedPointRef : IPointRef
    {
        public static IntersectedPointRef FromLineStroke(LineStroke stroke)
        {
            return new IntersectedPointRef {Stroke = stroke};
        }

        private LineStroke Stroke { get; set; }
        public int Id { get; set; }

        public Point? GetOnSurface(DrawingSurface drawingSurface)
        {
            var intersection3D = GetPoint3DOnSurface(drawingSurface);
            if (intersection3D == null) return null;

            return drawingSurface.Plane.ProjectTo2D(intersection3D.Value);
        }

        public Point3D? GetPoint3DOnSurface(DrawingSurface drawingSurface)
        {
            var start = Stroke.Start as SingleSurfacePointRef;
            var end = Stroke.End as SingleSurfacePointRef;
            if (start == null || end == null) return null;

            return drawingSurface.Plane.GetIntersection(start.Point, end.Point - start.Point, true);
        }

        public void SetOnSurface(DrawingSurface drawingSurface, Point point)
        {
        }
    }
}